#!/bin/sh
#
# Start or stop the NetMirror daemon.
#
# Written by Pablo Rincon Crespo <pablo.rincon.crespo@gmail.com>
#

### BEGIN INIT INFO
# Provides:          netmirror
# Required-Start:    $network
# Required-Stop:     
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Net Mirror monitor and traffic redirector
### END INIT INFO

PATH=/bin:/usr/bin:/sbin:/usr/sbin
NETMIRROR_BIN="/usr/bin/netmirror"
PIDFILE="/var/run/netmirror.pid"

[ ! -f /etc/default/rcS ] || . /etc/default/rcS
[ ! -f /etc/default/netmirror ] || . /etc/default/netmirror
test -f /lib/lsb/init-functions || exit 1
. /lib/lsb/init-functions

[ -s "${NETMIRROR_BIN}" ] || exit 0

case "${1}" in
("start")
    log_begin_msg "Starting Net Mirror daemon..."
    start-stop-daemon --start --quiet \
	  --pidfile $PIDFILE  --exec "${NETMIRROR_BIN}" -- ${NETMIRROR}
    case $? in
    (0)
	log_end_msg 0
	exit 0
	;;
    (1)
	log_end_msg 0
	exit 0
	;;
    (*)
	log_end_msg 1
	exit 1
	;;
    esac
    ;;
("stop")
    log_begin_msg "Stopping Net Mirror daemon..."
    start-stop-daemon --stop  --pidfile $PIDFILE --signal 2 --retry=1 --quiet --oknodo 
    rm $PIDFILE
    log_end_msg $?
    exit $?
    ;;
("restart" | "force-reload")
    "${0}" stop
    "${0}" start
    ;;
(*)
    log_success_msg "Usage: /etc/init.d/netmirror {start|stop|restart|force-reload}" >&2
    exit 3
    ;;
esac
#Net Mirror (c) 2009 Pablo Rincon Crespo
